package com.zzc.alfred.entity.weka;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import com.google.common.io.Files;
import com.zzc.alfred.entity.model.ProductIndexModel;
import com.zzc.alfred.entity.service.mysql.ProductIndexModelDBService;

import jodd.json.JsonParser;

public class WekaClient {

	static final String STEP1_PATH = "E:\\weka\\0309";

	/**
	 * { "商品名称":
	 * "戴尔（DELL）Vostro 3900 商用台式电脑整三年上门服务 品牌台式机 3900-R5938C I5/4G/1T/4G独显 E2216HV(21.5英寸)"
	 * , "商品编号": "10117587468", "店铺": " 华宏创天电脑专营店", "上架时间":
	 * "2016-02-16 15:54:11", "商品毛重": "6.0kg", "处理器": "intel其它", "硬盘容量":
	 * "（500G", "电脑类别": "商用电脑", "内存容量": "4G", "显卡": "其他", "系统": "Windows7",
	 * "显示器尺寸": "其他" }
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		ProductIndexModelDBService dbService = new ProductIndexModelDBService();
		List<ProductIndexModel> models = dbService.getAddedProductFormMahout();
		File file = new File(STEP1_PATH + "\\origin" + ".arff");
		if (!file.exists()) {
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		try {
			FileUtils.writeStringToFile(file, "@relation product", true);
			FileUtils.writeStringToFile(file, "@attribute productName	string", true);
			FileUtils.writeStringToFile(file, "@attribute shopName	string", true);
			FileUtils.writeStringToFile(file, "@attribute weight	string", true);
			FileUtils.writeStringToFile(file, "@attribute cpu	string", true);
			FileUtils.writeStringToFile(file, "@attribute disk	string", true);
			FileUtils.writeStringToFile(file, "@attribute memary	string", true);
			FileUtils.writeStringToFile(file, "@attribute gpu	string", true);
			FileUtils.writeStringToFile(file, "@attribute os	string", true);
			FileUtils.writeStringToFile(file, "@attribute view string", true);
			FileUtils.writeStringToFile(file, "@data", true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		for (ProductIndexModel model : models) {
			try {
				String params = model.getParams();
				Map<String, String> maps = new JsonParser().parse(params);
				FileUtils.writeStringToFile(file, maps.get("商品名称") + ",", true);
				FileUtils.writeStringToFile(file, maps.get("店铺") + ",", true);
				FileUtils.writeStringToFile(file, maps.get("商品毛重") + ",", true);
				FileUtils.writeStringToFile(file, maps.get("处理器") + ",", true);

				FileUtils.writeStringToFile(file, maps.get("硬盘容量") + ",", true);
				FileUtils.writeStringToFile(file, maps.get("内存容量") + ",", true);
				FileUtils.writeStringToFile(file, maps.get("显卡") + ",", true);

				FileUtils.writeStringToFile(file, maps.get("系统") + ",", true);
				FileUtils.writeStringToFile(file, maps.get("显示器尺寸") + "\r", true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
